﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_Category
    {
    	#region public properties
		[Required(ErrorMessage="Cate Code Required")]
		public string CateCode { get; set; }
		public string CateName { get; set; }
		public string Description { get; set; }
		public bool? Disabled { get; set; }
		#endregion

		#region constructor
		public pa_Category(){ }

		public pa_Category(IDataReader rd)
		{
			this.CateCode = rd["CateCode"].ToString();
			this.CateName = rd["CateName"].ToString();
			this.Description = rd["Description"].ToString();
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_Category.Create(CateCode, CateName, Description, Disabled);
        }

        private bool Update()
        {
            return DBpa_Category.Update(CateCode, CateName, Description, Disabled);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(CateCode != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(string CateCode)
        {
            return DBpa_Category.Delete(CateCode);
        }

        public static List<pa_Category> GetAll()
        {
            return ObjectClass.CreateList<pa_Category>(DBpa_Category.GetAll());
        }

        public static pa_Category GetByKey(string CateCode)
        {
            return ObjectClass.CreateInstance<pa_Category>(DBpa_Category.GetByKey(CateCode));
        }

        public static List<pa_Category> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_Category>(DBpa_Category.GetByTop(top, where, order));
        }
		#endregion
	}
}
